package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.common.security.annotation.RequiresPermissions;
import com.spzx.product.api.domain.vo.Brand;
import com.spzx.product.service.IBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "品牌接口管理")
@RestController
@RequestMapping("/brand")
public class BrandController extends BaseController {
    @Autowired
    IBrandService brandService;

    @Operation(summary = "获取品牌分页列表")
    @GetMapping("/list")
    public TableDataInfo getPageList(Brand brand) {
        startPage();
        List<Brand> brands = brandService.getPageList(brand);
        return getDataTable(brands);
    }

    @Operation(summary = "获取品牌详细信息")
    @GetMapping("{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(brandService.getBrandById(id));
    }

    @Operation(summary = "新增品牌")
    @PostMapping
    public AjaxResult addBrand(@RequestBody @Validated Brand brand) {
        int i = brandService.addBrand(brand);
        return AjaxResult.success(i);
    }

    @RequiresPermissions("product:brand:update")
    @Operation(summary = "修改品牌")
    @PutMapping
    public AjaxResult updateBrand(@RequestBody @Validated Brand brand) {
//        brand.setUpdateBy(SecurityUtils.getUsername());
        int i = brandService.updateBrand(brand);
        return toAjax(i);
    }

  @RequiresPermissions("product:brand:remove")
    @Operation(summary = "删除品牌")
    @DeleteMapping("/{ids}")
    public AjaxResult removeBrand(@PathVariable Long[] ids) {

        int i = brandService.deleteBrandByIds(ids);
        return AjaxResult.success(i);
    }

    @GetMapping("/getBrandAll")
    @Operation(summary = "获取全部品牌")
    public AjaxResult getBrandAll() {
        return success(brandService.getBRandAll());
    }
    @InnerAuth
    @Operation(summary = "获取全部品牌")
    @GetMapping("getBrandAllList")
    public R<List<Brand>> getBrandAllList(){
        return R.ok(brandService.getBRandAll());
    }

}
